<?php
namespace app\common\process;

class Agreement extends Base {
    public function index($code = null) {
        if(!$code) {
            $code = loader()->loadAny('request', 'Agreement')->get_code();
        }
        $site = config('site');
        $this->assign('site', $site);
        $row = loader()->loadModel('Agreement')->where(['code' => $code])->find();
        if(empty($row)) {
            $this->go404();
            return;
        }
        $row['content'] = str_replace('{$site.name}', $site['name'], $row['content']);
        $this->assign('row', $row);
        return $this->fetch();
    }

    public function go404() {
        abort(404, '页面不存在');
    }
}
